import os
from typing import Optional


def strEnv(key: str, defaultValue: Optional[str] = None) -> str:
    v = os.getenv(key)
    if v is None:
        if defaultValue is None:
            raise ValueError(f"env {key} is required")
        return defaultValue
    return v


def optionalStrEvn(key: str) -> Optional[str]:
    return os.getenv(key)


def floatEnv(key: str, defaultValue: Optional[float] = None) -> float:
    v = os.getenv(key)
    if v is None:
        if defaultValue is None:
            raise ValueError(f"env {key} is required")
        return defaultValue
    return float(v)


def optionalFloatEnv(key: str) -> Optional[float]:
    v = os.getenv(key)
    if v is None:
        return None
    return float(v)

_true_set = set(["true", "TRUE", "True", "t", "T", "yes", "YES", "Yes", "y", "Y", "1"])

def boolEnv(key: str, defaultValue: Optional[bool] = None) -> bool:
    v = os.getenv(key)
    if v is None:
        if defaultValue is None:
            raise ValueError(f"env {key} is required")
        return defaultValue
    if v in _true_set:
        return True
    return False